package lac.serviceuint.job.cfg;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("job")
public class ServiceUnitJob implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2378778445527927301L;
	
	private String id;
	@XStreamAsAttribute
	private String name;
	@XStreamAsAttribute
	private String describe;
	@XStreamAsAttribute
	private String serviceUnitName;
	@XStreamAsAttribute
	private String methodName;
	@XStreamAsAttribute
	private String cron;
	@XStreamAsAttribute
	private Boolean enable = true;
	@XStreamImplicit(itemFieldName="param")
	private List<ServiceUnitJobParam> params = new ArrayList<ServiceUnitJobParam>();
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescribe() {
		return describe;
	}
	public void setDescribe(String describe) {
		this.describe = describe;
	}
	public String getServiceUnitName() {
		return serviceUnitName;
	}
	public void setServiceUnitName(String serviceUnitName) {
		this.serviceUnitName = serviceUnitName;
	}
	public String getMethodName() {
		return methodName;
	}
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}
	public String getCron() {
		return cron;
	}
	public void setCron(String cron) {
		this.cron = cron;
	}
	public List<ServiceUnitJobParam> getParams() {
		if(params!=null && params.size()>1){
			params.sort(new Comparator<ServiceUnitJobParam>() {

				@Override
				public int compare(ServiceUnitJobParam o1, ServiceUnitJobParam o2) {
					return o1.getIndex() - o2.getIndex();
				}
			});
		}
		return params;
	}
	public void setParams(List<ServiceUnitJobParam> params) {
		this.params = params;
	}
	public Boolean getEnable() {
		return enable;
	}
	public void setEnable(Boolean enable) {
		this.enable = enable;
	}
	
	
}
